package org.q.threads;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class SubThreadWithExecption extends Thread {
	
	@Override
	public void run() {
		ExecutorService pool = Executors.newFixedThreadPool(5);
		for(int i=0;i<5;i++) {
			try {
				pool.submit(new SubThreadWithExecption2()).get();
			} catch (Exception e) {
				System.out.println("SubThreadWithExecption-"+e.getMessage());
			}
		}
	}
	
	public void process() throws InterruptedException {
		ExecutorService pool = Executors.newFixedThreadPool(5);

		List<Thread> threads = new ArrayList<Thread>();
		for(int i=0;i<5;i++) {
			Thread t = new SubThreadWithExecption2();
			threads.add(t);
			try {
				pool.execute(new SubThreadWithExecption2());
			} catch (Exception e) {
				System.out.println("SubThreadWithExecption-"+e.getMessage());
				continue;
			}
		}
		pool.shutdown();
		pool.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
		System.out.println("SubThreadWithExecption子线程执行结束， 关闭线程池");
		for(Thread t : threads) {
			System.out.println(t.getName()+"---结束！");
			t.interrupt();
		}
	}
	
}
